<template>
	<view>
		<view class="bartop"></view>
		<view class="cu-bar">
			<view class="action">
				<text class="cuIcon-back text-gray" @tap="goBack"></text> 返回
			</view>
			<view class="text-lg text-bold">
				报表详情
			</view>
			<view class="action"></view>
		</view>
		<view class="cu-list menu">
			<view class="cu-item">
				<text>班次：</text>
				<text>{{classes}}</text>
			</view>
			<view class="cu-item">
				<text>订单号：</text>
				<text>{{order_id}}</text>
			</view>
			<view class="cu-item">
				<text>产品名称：</text>
				<text>{{product_id}}</text>
			</view>
			<view class="cu-item">
				<text>机台编号：</text>
				<text>{{number}}</text>
			</view>
			<view class="cu-item">
				<text>单位：</text>
				<text>{{unit}}</text>
			</view>
			<view class="cu-item">
				<text>用料：</text>
				<text>{{material_id}}</text>
			</view>
			<view class="cu-item">
				<text>颜色/色粉：</text>
				<text>{{colour_id}}</text>
			</view>
			<view class="cu-item">
				<text>排产数量：</text>
				<text>{{order_number}}</text>
			</view>
			<view class="cu-item">
				<text>生产合格数量：</text>
				<text>{{qualified_quantity}}</text>
			</view>
			<view class="cu-item">
				<text>实际生产工时：</text>
				<text>{{working_hours}}</text>
			</view>
			<view class="cu-item">
				<text>残品数量：</text>
				<text>{{scrapped_part}}</text>
			</view>
			<view class="cu-item">
				<text>操作工：</text>
				<text>{{operator}}</text>
			</view>
			<view class="cu-item">
				<text>合格累计数量：</text>
				<text>{{accumulate_number}}</text>
			</view>
			<view class="cu-item">
				<text>换膜调试时间：</text>
				<text>{{debugging_time}}</text>
			</view>
			<view class="cu-item">
				<text>换料烘料时间：</text>
				<text>{{change_material_time}}</text>
			</view>
			<view class="cu-item">
				<text>其他异常时间：</text>
				<text>{{abnormal_time}}</text>
			</view>
			<view class="cu-item">
				<text>产品单重：</text>
				<text>{{weight}}</text>
			</view>
			<view class="cu-item">
				<text>备注：</text>
				<text>{{remarks}}</text>
			</view>
		</view>
		<!-- <view class="btn-group margin-top flex justify-between">
			<view class="button-content">
				<button class="bg-red round text-xs" @click="delForm">删除</button>
			</view>
			<view class="button-content">
				<button class="bg-purple round text-xs" @click="changeForm">修改</button>
			</view>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: null, // id
				classes: null, //班次
				order_id: null, //订单号
				product_id: null, //产品名称
				number: null, //机台编号
				unit: "个", //单位
				material_id: null, //用料
				colour_id: null, //颜色/色粉
				order_number: null, //排产数量
				qualified_quantity: null, //生产合格数量
				working_hours: null, //实际生产工时
				scrapped_part: null, //残品数量
				operator: null, //操作工
				accumulate_number: null, //合格累计数量
				debugging_time: null, //换模调试时间
				change_material_time: null, // 换料烘料时间
				weight: null, //产品单重
				abnormal_time: null, //其他异常事件
				remarks: null, //备注
				detailData: null
			}
		},
		methods: {
			onShow() {
				this.getFormDetail()
			},
			onLoad(options) {
				this.id = options.id
				this.operator = options.operator

			},

			getFormDetail() {
				this.$Request.post(this.$httpApi.form.detail + "?id=" +
					this.id).then(res => {
					if (res.code == 200) {
						let data = res.data
						console.log(data)
						this.detailData = data
						this.classes = data.classes == 1 ? "白班" : "晚班"
						this.order_id = data.orderId
						let colours = this.$cache.get("colour")
						colours.forEach((item) => {
							if (item.id == data.colourId) {
								this.colour_id = item.name
							}
						})
						let products = this.$cache.get("products")
						products.forEach((item) => {
							if (item.id == data.productId) {
								this.product_id = item.name
							}
							item.children.forEach((children) => {
								if (children.id == data.productId) {
									this.product_id = children.name
								}
							})
						})
						let materials = this.$cache.get("materials")
						materials.forEach((item) => {
							if (item.id == data.materialId) {
								this.material_id = item.name
							}
						})
						let machineNumbers = this.$cache.get("machineNumbers")
						machineNumbers.forEach((item) => {
							if (item.id == data.number) {
								this.number = item.name
							}
						})
						this.unit = data.unit
						this.order_number = data.orderNumber
						this.qualified_quantity = data.qualifiedQuantity
						this.working_hours = data.workingHours
						this.scrapped_part = data.scrappedPart

						this.accumulate_number = data.accumulateNumber
						this.debugging_time = data.debuggingTime
						this.change_material_time = data.changeMaterialTime
						this.weight = data.weight
						this.abnormal_time = data.abnormalTime
						this.remarks = data.remarks == null ? "无" : data.remarks
					}
				})
			},

			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			changeForm() {
				uni.navigateTo({
					url: "/pages/report_form/report_form?data=" + JSON.stringify(this.detailData)
				})
			},
			delForm() {
				uni.showModal({
					title: '提示',
					content: '确认删除该填报记录?',
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "确认", // 确认按钮的文字
					showCancel: true,
					success: ({
						confirm,
						cancel
					}) => {
						if (confirm) {
							this.$Request.post(this.$httpApi.form.delete + "?id=" + this.id).then(res => {
								if (res.code == 200) {
									uni.showToast({
										title: '删除成功',
										icon: '2|success,none|',
										mask: true
									})
									setTimeout(function() {
										uni.navigateBack({
											delta: 1
										});
									}, 1500);

								} else {
									uni.showToast({
										title: res.message,
										icon: 'none',
										mask: true
									})
								}
							})
						};
					}
				})
			}
		}
	}
</script>

<style>
	.cu-list.menu>.cu-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		min-height: 60rpx;
	}

	.button-content {
		width: 50%;
	}

	button {
		width: 60%;
	}
</style>
